package com.yunxi.controller.activiti;

import com.yunxi.activiti.service.ActivitiModelDubboService;
import com.yunxi.core.web.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@RestController
@Api(tags = "activiti:model", description = "工作流画图接口")
public class ActivitiModelController {

    protected static final Logger LOGGER = LoggerFactory.getLogger(ActivitiModelController.class);

//    @Reference(version = "${demo.service.version}",
//            application = "${dubbo.application.id}",
//            registry = "${dubbo.registry.address}",
//            url = "${dubbo.application.url}",
//            check = false,
//            timeout = 10000
//    )
    @Autowired
    private ActivitiModelDubboService activitiModelDubboService;
 
    /**
     * 新建一个空模型
     */
    @GetMapping("/create")
    @ApiOperation(value = "新建一个空模型")
    public Object newModel(HttpServletResponse response) throws IOException {
        String id= activitiModelDubboService.createNewModel();

        return ResponseUtil.ok(id);
    }
 
    /**
     * 获取所有模型
     */
    @GetMapping("/modelList")
    @ApiOperation(value = "获取所有模型")
    public Object modelList(){
        Object object= activitiModelDubboService.modelList();
       return object;
    }
 
    /**
     * 发布模型为流程定义
     */
    @GetMapping("/deploy")
    @ApiOperation(value = "发布模型为流程定义")
    public Object deploy(String modelId) throws Exception {
        String msg= activitiModelDubboService.deploy(modelId);

 
        return msg;
    }
 
    /**
     *  启动流程
     */
    @GetMapping("/start")
    @ApiOperation(value = "启动流程")
    public Object startProcess(String keyName) {
        Object object= activitiModelDubboService.startActProcess(keyName);
      return object;
    }
 
    /**
     *  提交任务
     */
    @GetMapping("/run")
    @ApiOperation(value = "提交任务")
    public Object run(String processInstanceId) {
        Object object= activitiModelDubboService.runAct(processInstanceId);
       return  object;
    }
}